<?php
/*
 * Affiche la liste des modes sous forme de boutons
 */
?>
<div class="radioBtn">
    <?php
    $conditions = array('order' => 'ordre');
     $conditions['condition'] = 'ordre > 0';
    if ($this->manuel) {
	  $conditions['condition'] .= ' AND manuel = 1';
    }

    $options = array(
	  'template' => '{input}{label}', 'separator' => '',
    );

    if ($this->updateOnClick) {
	  //$options['onclick'] = 'javascript:this.form.action=\'/chauffage/zone/control\';this.form.submit()';
	  $options['onclick'] = "js:updateForm($(this));";

	  Yii::app()->clientScript->registerScript('updateForm', "
		    function updateForm(caller) {
		    
			  var currentLabel = $('label[for=\'' + caller.attr('id') + '\']')
			  
			  currentLabel.fadeTo(0, 0.5);
			  
			  var data=$('#zone-form').serialize();

			  $.ajax({
				type: 'POST',
				url: '/chauffage/zone/control',
				data:data,
				success:function(data){
				   //$('#ajaxReturn').html(data);
				   currentLabel.fadeTo(0, 1);
				},
				error: function(data) { // if error occured
				    $('#ajaxReturn').html(data);
				    currentLabel.fadeTo(0, 1);
				},
				dataType:'html'
			  });
			  
			
			
		    }", CClientScript::POS_END);
    }


    echo CHtml::activeRadioButtonList(
		$this->model, $this->attribute, CHtml::listData(Mode::model()->findAll($conditions), 'id', function($mode) {
				return $mode->getPicto();
			  }), $options
    );
    ?>
</div>

